import {HttpClient} from '@angular/common/http';
import {Injectable} from '@angular/core';
import {InhouseModel,Organize} from "../../../model/pages/performance/inhouse-performance";
import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';


@Injectable()
export class InhousePerformanceProvider {
    private inhouseData:Array<any>= [
        {
          name: 'first',
          options: [
            { text: '全国', value: '0', parentVal:'null' },
            { text: '四川省', value: '1', parentVal:'null' },
            { text: '云南省', value: '2', parentVal:'null' }
          ]
        },{
          name: 'second',
          options: [
            { text: '全部', value: '1-0', parentVal:'1'},
            { text: '成都', value: '1-1', parentVal:'1' },
            { text: '绵阳', value: '1-2', parentVal:'1' },
            { text: '全部', value: '2-0', parentVal:'2' },
            { text: '昆明', value: '2-1', parentVal:'2' },
            { text: '大理', value: '2-2', parentVal:'2' }
          ]
        },{
          name: 'third',
          options: [
            { text: '全部', value: '1-1-0', parentVal:'1-1' },
            { text: '成都1', value: '1-1-1', parentVal:'1-1' },
            { text: '成都2', value: '1-1-2', parentVal:'1-1' },
            { text: '全部', value: '1-2-0', parentVal:'1-2' },
            { text: '绵阳1', value: '1-2-1', parentVal:'1-2' },
            { text: '绵阳2', value: '1-2-2', parentVal:'1-2' },
            { text: '全部', value: '2-1-0', parentVal:'2-1' },
            { text: '昆明1', value: '2-1-1', parentVal:'2-1' },
            { text: '昆明2', value: '2-1-2', parentVal:'2-1' },
            { text: '全部', value: '2-2-0', parentVal:'2-2' },
            { text: '大理1', value: '2-2-1', parentVal:'2-2' },
            { text: '大理2', value: '2-2-2', parentVal:'2-2' }
          ]
        }
      ];

    constructor(public http: HttpClient) {
    }

    /**
     * 获取组织架构数据
     */
    getorganizeData():Observable<Array<Organize>>{
        return Observable.create(observer=>{
            this.http.get("/employee/v1/userOrganize").subscribe(data=>{
              // observer.next(this.inhouseData);
              observer.next(data);
              console.log(data);
            },() => {
              observer.next(null);
          });
        });
    }

    /**
     * 获取内勤数据
     */
    getInhouseData(filter):Observable<any>{
      let code:Array<any>=[];
      filter['code'].split(' ').forEach(item=>{
        if(item !== 'null' && item !== '') code.push(item);
      });
      if(filter.type==='D') filter.time='';
      console.log(code);
      return this.http.get(`/achieve/v1/cmsAchieve?code=${code[code.length-1]}&type=${filter['type']}&time=${filter['time'].replace(/-/g,'')}`);
      // return this.http.get("/achieve/v1/cmsAchieve?code=PBJ&type=M&time");
    }
}